package router

import (
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"strconv"
	"study/server/global"
	"study/server/middleware"
	"study/server/router/common_router"
	"study/server/router/user_router"
)

func RunRouter() {
	sys := global.Config.System
	gin.SetMode(sys.Mode)
	router := gin.Default()
	IP := sys.IP
	Port := sys.Port
	// 静态路由 -- 将路由ReStatic映射到static目录
	router.Static("/uploads", "uploads")
	// 根路由组
	rootGroup := router.Group("/api")
	// 公共路由
	common_router.CommonRouter(rootGroup)
	{
		// 用户路由
		userRouter := rootGroup.Group("/user", middleware.CheckTokenWhetherBlack())
		user_router.UserRouter(userRouter)
	}

	logrus.Infof("服务启动成功:IP:%s  Port:%d", IP, Port)
	_ = router.Run(IP + ":" + strconv.Itoa(Port))

}
